[@plaintext.layout title="QuickView"]

h1. Simple List/Sequence
[#assign xs = [0,1,2,3,4,5,6,7,8,9]/]
size: ${xs?size}
first: ${xs[0]}, ${xs?first}
last: ${xs?last}
all: [#list xs as x]${x}, [/#list]
sublist: [#list xs[3..5] as x]${x} [/#list]
sublist til end: [#list xs[3..] as x]${x} [/#list]

h2. looping with implicit variable: _index and _has_next
Only output sep if it's not LAST [[#list xs as x]'${x}'[#if x_has_next],[/#if][/#list]]
list with index
[#list xs as x]
#${x_index+1}: '${x}'
[/#list]

Breaking loop if x > 5: 
[#list xs as x]
	[#if (x > 5)]
		[#break]
	[#else]
		${x}
	[/#if]
[/#list]

h2. Range
[#assign nums = 1..5 /]
range: [#list nums as x]${x} [/#list]
[#-- [#assign nums = (1..5,2) /] --]
range with step?: [#list nums as x]${x} [/#list]

h2. Chunk
[#assign seq = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']]

[#list seq?chunk(4) as row]
  [#list row as cell]${cell} [/#list]
[/#list]

[#list seq?chunk(4, '-') as row]
  [#list row as cell]${cell} [/#list]
[/#list]

h2. Contains/Exists Check
[#assign x = ["red", 16, "blue", "cyan"]]
"blue": ${x?seq_contains("blue")?string("yes", "no")}
"yellow": ${x?seq_contains("yellow")?string("yes", "no")}
16: ${x?seq_contains(16)?string("yes", "no")}
"16": ${x?seq_contains("16")?string("yes", "no")}

h1. Sorting elements in list
[#assign ls = [
  {"name":"whale", "weight":2000},
  {"name":"Barbara", "weight":53},
  {"name":"zeppelin", "weight":-200},
  {"name":"aardvark", "weight":30},
  {"name":"beetroot", "weight":0.3}
]]
Order by name:
[#list ls?sort_by("name") as i]
- ${i.name}: ${i.weight}
[/#list]

Order by weight:
[#list ls?sort_by("weight") as i]
- ${i.name}: ${i.weight}
[/#list]  

h2. Deep sort
[#assign members = [
    {"name": {"first": "Joe", "last": "Smith"}, "age": 40},
    {"name": {"first": "Fred", "last": "Crooger"}, "age": 35},
    {"name": {"first": "Amanda", "last": "Fox"}, "age": 25}]]
Sorted by name.last: 
[#list members?sort_by(['name', 'last']) as m]
- ${m.name.last}, ${m.name.first}: ${m.age} years old
[/#list]

[/@plaintext.layout]
